package game.state.gameplay;

import engine.input.Keys;
import engine.input.Mouse;
import game.component.Motion;
import game.component.Position;
import game.component.Rotation;
import math.Maths;

public class Player 
{
    
    public final float kHeight;
    
    private Position pos;
    public Position pos() 
    {
        return pos;
    }
    
    private Rotation rot;
    public Rotation rot() 
    {
        return rot;
    }
    
    private Motion mot;
    public Motion mot() 
    {
        return mot;
    }
    
    public boolean physEnabled;
    
    public Player() 
    {
        pos = new Position();
        pos.setStart(0.0f, 0.0f, 0.0f);
        rot = new Rotation();
        rot.setStart(0.0f, Maths.PI, 0.0f);
        mot = new Motion();
        mot.bindSpeed(5.0f);
        kHeight = 2.0f;
        physEnabled = true;
    }
    
    public void update(Mouse mouse, Keys keys, float timeCycle) 
    {
        float dXRot = Maths.cap(mouse.dy() * mouse.mouseSens(), -Maths.PI_OVER_2, Maths.PI_OVER_2);
        float dYRot = Maths.mod(mouse.dx() * mouse.mouseSens(), Maths.PI_TIMES_2);
        rot.update(dXRot, dYRot, 0.0f);
        
        mot.update(keys, pos, rot, timeCycle);
    }
    
    public void reset() 
    {
        pos.reset();
        rot.reset();
        mot.reset();
    }
    
    public float getViewX() 
    {
        return pos.pos().x;
    }
    
    public float getViewY() 
    {
        return pos.pos().y + kHeight;
    }
    
    public float getViewZ() 
    {
        return pos.pos().z;
    }
    
}
